﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using iMapa.Helper;

namespace Testing
{
    public partial class Prepare : Form
    {
        

        private Capture capture = new Capture(Program.file);
        private int length; 
        private int position=0;
        private PointRegister pr = new PointRegister("test");
        
        public Prepare()
        {
            length = (int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_COUNT);
            Image<Bgr, Byte> frame = capture.QueryFrame();
            InitializeComponent();
            pictureBox1.FunctionalMode = ImageBox.FunctionalModeOption.Minimum;
            pictureBox1.Image = frame;
            label1.Text = "" + position + "/" + length;
        }


        private void GotoFrame()
        {
            position = (int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_POS_FRAMES);
            
            Image<Bgr, Byte> frame = capture.QueryFrame();
            
            pictureBox1.Image = frame;
            label1.Text = "" + position + "/" + length;

        }

        private void setPointPosition(object sender, MouseEventArgs  e)
        {
            pr.addPoint(new Point(e.X, e.Y), position);
            GotoFrame();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            GotoFrame();
        }

        private void savebutton_Click(object sender, EventArgs e)
        {
            ObjectXMLSerializer<PointRegister>.Save(pr, Program.file + ".xml");
        }

    }
}
 